//
//  WBNavigationController.swift
//  仿写微博
//
//  Created by Apple on 17/6/30.
//  Copyright © 2017年 tuimao. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的NavigationBar
        navigationBar.isHidden = true
    }
    @objc fileprivate func popprisentVC() {
        popViewController(animated: true)
    }
    
    //重写push
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //不是栈底部的根控制器的时候，也就所有tabbar上vc都加载完毕时候，这时候childViewControllers才有值
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as? WBBaseViewController {
            //设置返回的按钮
            var title = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? "返回"
            }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popprisentVC), isback: true)
            }
        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    
}
